package com.pmsystem.util.account;

import java.util.Map;



public class CashAccountImpl implements CashAccount {

	@Override
	public Float ParkingCashAccount(int rule, Float time, Map<String, Float> map) {
		
		Float param1=map.get("param1");
		Float param2=map.get("param2");
		Float param3=map.get("param3");
		Float param4=map.get("param4");
		Float param5=map.get("param5");
//		Float param6=map.get("param6");
		
		//规则1
		if(rule==1) {
			//只算起步价
			if(time<param1) {
				return param2;
			}
			//起步价+每个时段的总费用
			if(time>param1&&param3!=0) {
				return param2+(float)Math.ceil((time-param1)/param4)*param3;
			}
		}
		
		//规则2
		if(rule==2) {
			//按时收费
			if(time<param1&&param3!=0) {
				return param2*(float)Math.ceil((time/param3));
			}else {
				//超时罚款
				return param2*(float)Math.ceil((time/param3))+param4;
			}
		}
		
		//规则3
		if(rule==3) {
			//按时收费
			if(time<param1&&param3!=0) {
				return param2*(float)Math.ceil((time/param3));
			}else {
				//超时收取固定费用
				return param4;
			}
		}
		
		//规则4
		if(rule==4) {
			//低时段大于高时段是输入非法的
			if(param1<param3) {
				//固定时段固定费用
				if(time<param1) {
					return param2;
				}else if(time<param3) {
					return param4;
				}else {
					return param5;
				}
			}else {
				return null;
			}
		}
		//规则5
		if(rule==5) {
			return param1;
		}
		
		return null;
	}

	
	
	
	@Override
	public Float ConsumeCashAccount(int rule, Float waste, Map<String, Float> map) {
		
		Float param1=map.get("param1");
		Float param2=map.get("param2");
		Float param3=map.get("param3");
		Float param4=map.get("param4");
		Float param5=map.get("param5");
		Float param6=map.get("param6");
		//规则6 用多少收多少
		if(rule==6) {
			return waste/param2*param1;
		}
		
		//规则7 阶梯收费
		if(rule==7) {
			if(param3<param5) {
				if(waste<=param3) {
					return waste/param2*param1;
				}else if(waste<=param5) {
					return param3/param2*param1+(waste-param3)/param2*param4;
				}else {
					return param3/param2*param1+(param5-param3)/param2*param4+(waste-param5)/param2*param6;
				}
			}else {
				return null;
			}
		}
		
		//规则8 按人头，户数收固定费用
		if(rule==8) {
			return waste*param1;
		}
		return null;
	}
}
